package com.xyb.common.config;

import com.xyb.utils.IdUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class BeanConfig {

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Bean
    public IdUtils idUtils(){
        return new IdUtils();
    }

    public static void main(String[] args) {
        /*String str = Base64Utils.base64Encode( "123456");
        System.out.println("str = " + str);
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String encode = encoder.encode("MTIzNDU2");
        String encode1 = encoder.encode(str);

        System.out.println(encode);  //$2a$10$sKtMLyE3sD9bOBLWw5SGguKQy40lXaHyWQZp2OEBCxJd4znWDMFam
        System.out.println(encode1); //$2a$10$46myDiuVKQ1Jg7R0ByAStOL0zNs9qHeNU1BHw.VQs3BvYuPGxIPum*/

        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

        String encode = encoder.encode("123456");
        //$2a$10$gRqPIXKMo6BuO.fLVP9Y6.U2FkHXlzM3f1nkjK1k4FeUfAvaKGXP6
        //$2a$10$EP7FszGtL15m2SVWA9jJ.ecVmqFtvCXGA0Mjyve..LS5y/bYtEDeW

        boolean b1 = encoder.matches("123456", "$2a$10$gRqPIXKMo6BuO.fLVP9Y6.U2FkHXlzM3f1nkjK1k4FeUfAvaKGXP6");
        boolean b2 = encoder.matches("123456", "$2a$10$EP7FszGtL15m2SVWA9jJ.ecVmqFtvCXGA0Mjyve..LS5y/bYtEDeW");

        /*boolean b2 = encoder.matches(str, "$2a$10$46myDiuVKQ1Jg7R0ByAStOL0zNs9qHeNU1BHw.VQs3BvYuPGxIPum");*/

        System.out.println("b1 = " + b1);
        System.out.println("b2 = " + b2);

        //System.out.println("encode = " + encode);
    }

}
